﻿<!DOCTYPE html>
<html>
<head>
    <title>智慧社区</title>
    <link href="/static/css/framework-font.css" rel="stylesheet"/>
    <script src="/static/js/jquery-2.1.1.js"></script>
    <script src="/static/bootstrap/js/bootstrap.js"></script>
    <link href="/static/bootstrap/css/bootstrap.min.css" rel="stylesheet"/>
    <script src="/static/js/jquery.cookie.js"></script>
    <link href="/static/css/framework-theme.css" rel="stylesheet"/>
    <script src="/static/js/framework-ui.js"></script>
    <script src="/static/js/framework-clientdata.js"></script>
    <!--引用layui弹框插件-->
    <script src="/static/layui/layui.all.js"></script>
    <script src="/static/layui/layui.js"></script>
    <link href="/static/layui/css/layui.css" rel="stylesheet"/>
    <script src="/static/layui/lay/modules/layer.js"></script>

        {if condition="$swidthStyle eq 0"}
    <link href="/static/css/pattern/public.css" rel="stylesheet"/>
    {else/}
        {if condition="$swidthStyle eq 0"}
    <link href="/static/css/pattern/public.css" rel="stylesheet"/>
    {else/}
    <link href="/static/css/default/public.css" rel="stylesheet"/>
    {/if}
    {/if}
</head>
<body>

<div class="newtest">
    <div class="container new_serach">
        {volist name="powerList" id="vo"}
        <a class="btn btn-primary btn-sm" href="{$vo['url']}">{$vo.name}</a>
        {/volist}
    </div>

    <div class="container new_serach">
        <span> 排序：</span>
        <div class="layui-inline layui-form"  style="width:80px;">
            <select name="sort" lay-filter="sort">
                <option value="id" {if condition="$sort eq 'id'"} selected {/if}>综合</option>
                <option value="size" {if condition="$sort eq 'size'"} selected {/if}>大小</option>
                <option value="addtime" {if condition="$sort eq 'addtime'"} selected {/if}>上传时间</option>
            </select>
        </div>

        <span> 类型：</span>
        <div class="layui-inline layui-form"  style="width:80px;">
            <select name="type" lay-filter="type">
                <option value="0" {if condition="$type eq 0"} selected {/if}>全部</option>
                <option value="1" {if condition="$type eq 1"} selected {/if}>文档</option>
                <option value="2" {if condition="$type eq 2"} selected {/if}>压缩包</option>
                <option value="3" {if condition="$type eq 3"} selected {/if}>图片</option>
                <option value="4" {if condition="$type eq 4"} selected {/if}>视频</option>
                <option value="5" {if condition="$type eq 5"} selected {/if}>音频</option>
            </select>
        </div>
        <button class="layui-btn layui-btn-sm" data-type="reload">搜索</button>
    </div>


    <div class="new_main">

        <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container">
                <button class="layui-btn layui-btn-sm layui-btn-danger" lay-event="getCheckLength">批量删除</button>
            </div>
        </script>

        <table class="layui-hide" id="demo" lay-filter="demo"></table>
    </div>
</div>


</body>
<script src="/static/js/index.js"></script>
<script src="/static/js/indextab.js"></script>
<script src="/static/js/pace.min.js"></script>
<script>
    layui.use(['form', 'jquery', 'layer', 'laydate','table'], function () { //独立版的layer无需执行这一句
        var $ = layui.jquery, layer = layui.layer;
        var form = layui.form;
        var laydate = layui.laydate;
        var table = layui.table //表格
        //日期范围
        laydate.render({
            elem: '#test6'
            , range: true
        });

        var sort = 0;
        form.on('select(sort)',function (data) {
            sort = data.value;
        })

        var type = 0;
        form.on('select(type)',function (data) {
            type = data.value;
        })

        //搜索操作
        $('.layui-btn').click(function () {
            table.reload('demo', {
                url:"{:URL('admin/file/index')}"
                // ,methods:"post"
                , request: {
                    pageName: 'page' //页码的参数名称，默认：page
                    , limitName: 'pageSize' //每页数据量的参数名，默认：limit
                }
                , where: {
                    sort: sort,
                    type: type,
                }
                , page: {
                    curr: 1
                }
            });
        });

        table.render({
            toolbar: '#toolbarDemo', //开启头部工具栏，并为其绑定左侧模板
            defaultToolbar: [],
            elem: '#demo', // 表格id
            url:"{:URL('admin/file/index')}",
            where:{show:'list'},
            title: '单元列表',
            page: true, // 树形表格一般是没有分页的
            cols: [[
                {type: 'checkbox', fixed: 'left'}
                ,{field: 'id', title: 'ID',  sort: true, fixed: 'left',width:80}
                ,{field: 'name', title: '文件名',width:350}
                ,{field: 'ContentType', title: '文件类型'}
                ,{field: 'size', title: '大小'}
                ,{field: 'table', title: '所属角色'}
                ,{field: 'add_id', title: '上传人'}
                ,{field: 'addtime', title: '上传时间',sort: true}
            ]],
            done: function() {
                layer.closeAll('loading');
            }
        });

        //头工具栏事件
        table.on('toolbar(demo)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id);
            switch(obj.event){
                case 'getCheckLength':
                    var data = checkStatus.data;
                    var id=[];
                    for (var i = 0; i < data.length; i++) {
                        id[i] = data[i].id;
                    }
                    layer.confirm('该操作会影响引用该图片的内容，请谨慎操作', function(index){
                        delOperation(id,obj,index,1);
                    });
                    break;

            };
        });

        //删除
        function delOperation(id,obj,index,reload=0) {
            $.ajax({
                type: "post",
                url: "{:URL('admin/file/delFile')}",
                data: {id:id},
                dataType: "json",
                success: function(data){
                    layer.alert(data.msg);
                    if(data.code==0){
                        if(reload==0){
                            obj.del();
                            layer.close(index);
                        }else{
                            //执行重载
                            table.reload('demo');
                            layer.close(index);
                        }
                    }
                }
            });
        }

    });

</script>

</html>
